package com.card.log;

import java.util.Date;
import java.util.List;

import com.card.game.room.AbstractRoom;
import com.card.user.User;
import com.card.user.UserBase;
import com.card.user.UserUtils;
import com.google.common.collect.Lists;
import com.xiaoao.net.db.Entity;
import com.xiaoao.net.db.FilterOperator;
import com.xiaoao.net.db.Query;
import com.xiaoao.net.db.SortDirection;
import com.xiaoao.net.db.mongo.MongodbManager;

public class LogUtils {
	public static void addSpendLog(UserBase user,LogType logType,int gold) {
		UserGoldLog log = new UserGoldLog(user, gold, logType);
		log.save();
	}
	
	public static void addSpendLog(UserBase user,String info,int gold) {
		UserGoldLog log = new UserGoldLog(user, gold, info);
		log.save();
	}
	public static int MaxNum = 1000;
//	public static List<UserGoldLog> getGoldLog(String userId,int pageNum) {
//		Query query = new Query("UserGoldLog");
//		query.addFilter("userId", FilterOperator.EQUAL, userId);
//		query.addSort("addTime", SortDirection.ASCENDING);
//		query.setLimit(MaxNum);
//		query.setSkip(MaxNum*(Math.max(pageNum-1, 0)));
//		List<Entity> enlis = MongodbManager.getInstance().queryEntity(query);
//		List<UserGoldLog> resultList = Lists.newArrayList();
//		for (Entity e : enlis) {
//			resultList.add(new UserGoldLog(e));
//		}
//		return resultList;
//	}
	
	public static List<UserGoldLog> getGoldLog(String userId,int maxNum) {
		Query query = new Query("UserGoldLog");
		query.addFilter("userId", FilterOperator.EQUAL, userId);
		query.addSort("addTime", SortDirection.DESCENDING);
		query.setLimit(maxNum);
		List<Entity> enlis = MongodbManager.getInstance().queryEntity(query);
		List<UserGoldLog> resultList = Lists.newArrayList();
		for (Entity e : enlis) {
			resultList.add(new UserGoldLog(e));
		}
		return resultList;
	}
	public static void main(String[] args) {
		User user = UserUtils.getUserByImei("1");
		for (int i = 0; i < 3; i++) {
			addSpendLog(user, LogType.GMFK.getDesc()+"123", 1);
		}
	}
}
